package hanlder

import (
	"github.com/gin-gonic/gin"
	"platform-sys/model"
)

func Add(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")

	if username == "" || password == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "用户名或密码为空",
		})
		return
	}

	data := model.User{
		Username: username,
		Password: password,
	}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
func List(c *gin.Context) {
	var user []model.User
	model.DB.Debug().Find(&user)
	c.JSON(200, gin.H{
		"code": 200,
		"data": user,
		"msg":  "success",
	})
}
